package reflect;


import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class ReflectDemo1
{
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException
    {
        Class stringClass = String.class;
        String name = stringClass.getName();  // 获取类的完全限定名
        System.out.println(name);
        name = stringClass.getSimpleName();  // 获取类的类名
        System.out.println(name);

        String s = "11";
        Class sClass = s.getClass();
        System.out.println(sClass.getSuperclass());   // getSuperClass 获取父类类名

        // 获取包的相关信息
        Package aPackage = sClass.getPackage();
        System.out.println(aPackage.getName());   // 获取包的名字


        System.out.println("-------------------------------------");
        Method[] methods = sClass.getMethods();
        for (Method method : methods)
        {
            System.out.println(method.getName());
            System.out.println(method.getReturnType());
            System.out.println(Arrays.toString(method.getParameterTypes()));
            System.out.println(method.getParameterCount());
        }


        System.out.println("-----------------------------------------");
        Class arrayListClass = ArrayList.class;
        Method[] methods1 = arrayListClass.getMethods();
        for (Method method : methods1)
        {
            System.out.println(method.getName() );
            System.out.println(method.getReturnType());
            System.out.println(method.getParameterCount());
        }
        System.out.println("please input a className :");
        Scanner scanner = new Scanner(System.in);
        Class cls = Class.forName(scanner.nextLine());
        System.out.println(cls.getName());
        System.out.println(cls.getSimpleName());

        Class ss = String.class;
        String o = (String) ss.newInstance();
        o = "2123";
        System.out.println(o);


    }
}
